package at.fhh.se.tjr.client.view;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import at.fhh.se.tjr.client.model.MoteWrapper;
public class MoteWrapperPanel extends JPanel{

	private static final long serialVersionUID = 6696133860036379591L;
	
	private MoteWrapper wrapper;
	private JLabel id, distance;
	private JTable table = new JTable();
	private DefaultTableModel model = new DefaultTableModel();
	
	
	public MoteWrapperPanel(){
		table.setModel(model);
		model.addColumn("Registered Motes");
		this.setLayout(new GridLayout(4,1));	
		id = new JLabel("Mote ID: ");
		distance = new JLabel("Distance: ");
		JScrollPane scrolli =new JScrollPane(table);
		this.add(id);
		this.add(distance);
		this.add(scrolli);
	}
	
	public void reloadWrapper(){
		if ( wrapper!= null){
			id.setText(String.valueOf(wrapper.getId()));
			distance.setText(String.valueOf(wrapper.getDistance()));
			table.removeAll();
		}
		table.repaint();
		this.repaint();
	}

	
	public void registerID(long id){
		Object[] row = {id};
		model.addRow(row);
		table.repaint();
		this.repaint();
	}
	
	public MoteWrapper getWrapper() {
		return wrapper;
	}

	public void setWrapper(MoteWrapper wrapper) {
		this.wrapper = wrapper;
		this.reloadWrapper();
	}
	
	public void setDistance(Long distance){
		this.distance.setText("Distance: " + String.valueOf(distance));
	}
	
}
